package com.work.tqyb.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.work.tqyb.databinding.ItemAirHBinding;
import com.work.tqyb.http.response.AirHistoryHoursResponse;

import java.util.ArrayList;

public class ActivityAir24HourAdapter extends BaseAdapter {

    public ArrayList<AirHistoryHoursResponse.Result.CityAirInfoBean> cityList;


    @Override
    public int getCount() {
        return cityList == null ? 0 : cityList.size();
    }

    @Override
    public AirHistoryHoursResponse.Result.CityAirInfoBean getItem(int position) {
        return cityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ActivityAir24HourAdapter.ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ActivityAir24HourAdapter.ViewHolder();
            viewHolder.binding = ItemAirHBinding.inflate(LayoutInflater.from(parent.getContext()));
            convertView = viewHolder.binding.getRoot();
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ActivityAir24HourAdapter.ViewHolder) convertView.getTag();
        }
        AirHistoryHoursResponse.Result.CityAirInfoBean info = cityList.get(position);
        viewHolder.binding.tvName.setText(info.Time);
        viewHolder.binding.tvCO.setText("一氧化碳，mg/m3:" + info.CO);
        viewHolder.binding.tvNO2.setText("二氧化氮，μg/m3:" + info.NO2);
        viewHolder.binding.tvO3.setText("臭氧，μg/m3:" + info.O3_8h);
        viewHolder.binding.tvPM10.setText("可吸入颗粒物，μg/m3:" + info.PM10);
        viewHolder.binding.tvPM25.setText("细颗粒物，μg/m3:" + info.PM2_5);
        viewHolder.binding.tvSO2.setText("二氧化硫，μg/m3:" + info.SO2);
        viewHolder.binding.tvAQI.setText("空气质量指数:" + info.AQI);
        viewHolder.binding.tvPrimaryPollutant.setText("首要污染物:" + info.PrimaryPollutant);
        viewHolder.binding.tvMeasure.setText("建议措施描述:" + info.Measure);
        viewHolder.binding.tvUnheathful.setText("健康指引描述:" + info.Unheathful);
        convertView=  viewHolder.binding.getRoot();
        return convertView;
    }

    class ViewHolder {
        ItemAirHBinding binding;
    }


}
